/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * This class is for insert a venue into venue table 
 * modified by  Jenny
 */
package ticketmaster.businesslogic;

import java.util.Collection;
import javax.sql.RowSet;
import ticketmaster.dao.DAOFactory;
import ticketmaster.dao.VenueDAO;
import ticketmaster.dataobject.Venue;

/**
 *
 * @author Varadha
 */
public class VenueController {

    /*
     * Modified by Jenny for addVenue and deleteVenue methods 
     */
  //private VenueDAO venueDAO = DAOFactory.getInstance().getVenueDAO() ;
  public int addVenue(Venue venue)
  {
      VenueDAO venueDAO = DAOFactory.getInstance().getVenueDAO() ;
      int newid = 0 ; //to store generated venueid if the insertion is successful
      Venue tVenue = new Venue() ;
      tVenue.setName(venue.getName()) ;
      tVenue.setLocation(venue.getLocation());
      tVenue.setType(venue.getType());
      Collection<Venue> VenueCollection = venueDAO.getVenuesDO(tVenue);
      if(!VenueCollection.isEmpty())
      {
          return 0 ;
      }
      else
      {
          newid = venueDAO.insertVenue(tVenue) ;
          if(newid == 0)
          {
              return 0 ;
          }
          else
          {
              return newid;
          }

      }


  }
  public boolean deleteVenue(Venue venue)
 {
     VenueDAO venueDAO = DAOFactory.getInstance().getVenueDAO() ;
     return venueDAO.delete(venue) ;
  }

    public Collection<Venue> getAllVenues()
    {
        VenueDAO venueDAO = DAOFactory.getInstance().getVenueDAO();
        Venue venue = new Venue();
        return venueDAO.getVenuesDO(venue);
    }

}
